Commands and menusΒΆ
Create a new command
Use command.create to create new commands:
local dosomething = command.create ("DoSomething")
-- isenabled tells if the command can be run
function dosomething:isenabled ()
return true
end
-- action is executed when we run the command
function dosomething:action ()
print ("Something done.")
end
Add a command to a menu
Use MainMenu:addcommand
:
-- First test that MainMenu really exists
-- When running --nogui MainMenu does not exist and
-- the script will crash!
if MainMenu then
MainMenu:addcommand (dosomething, "MyMenu", "MySubMenu")
end
See also command.menu.
Invoke a command
Use command.executebyshortname
:
command.executebyshortname ("DoSomething")